import React from 'react';
import ReactDOM from 'react-dom/client';
import {registerMicroApps, initGlobalState, MicroAppStateActions,RegistrableApp} from 'qiankun';


import './index.css';
import {
    RouterProvider,
} from "react-router-dom";
import router from './router/router-index'
import { message } from 'antd';
import microData from './store/micro-data';

const loader = (loading:boolean)=>{
    console.log(loading)
}


registerMicroApps([
    {
        name: 'my-sub-app',
        entry: 'http://localhost:4003',
        container: '#my-micro-container',
        //当路由到这里时激活子应用
        activeRule: '/auth/subapp',
        loader
    },
],{
    beforeLoad : [(app) => {
        message.info(`开始   加载    子应用  ------  ${app.name}`);
        return Promise.resolve();
    }],
    afterMount: [(app) => {
        message.info(`完毕！！！！   加载    子应用完毕  -----  ${app.name}`);
        microData.updateLoading(false);
        return Promise.resolve();
    }],
    afterUnmount: [(app) => {
        message.info(`子应用已卸载 ------  ${app.name}`);
        return Promise.resolve();
    }],
});

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);





root.render(
    <React.StrictMode>
        <RouterProvider router={router} />
    </React.StrictMode>
)




